package com.kejiguan.ui;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.db.chart.model.BarSet;
import com.kejiguan.ui.model.ExhibitionRunItem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by YYY on 16/7/27.
 */
public class ExhibitinRunDataPreviewColumnChartActivity extends Activity{

    private TextView titleView;
    private com.kejiguan.ui.widget.BarChartView barChartView;
    private int type=1;
    private List<ExhibitionRunItem> exhibitionRunItems;

    private BarSet barSet;

    private float minValue,maxValue;
    @Override
    public void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);
        getIntentData();
        if (null==exhibitionRunItems)
        {
            finish();
        }
        setContentView(R.layout.activity_exhibition_rundate_preview_colum_layout);
        titleView= (TextView) findViewById(R.id.titile);
        barChartView= (com.kejiguan.ui.widget.BarChartView) findViewById(R.id.bar_chart_view);
        generateData();

        List<ExhibitionRunItem> backExhibitionRunItems=new ArrayList<>(exhibitionRunItems);
        for (int i=0;i<backExhibitionRunItems.size();i++)
        {
            ExhibitionRunItem exhibitionRunItem=backExhibitionRunItems.get(i);
            exhibitionRunItem.setCurrentType(type);
        }

        Collections.sort(backExhibitionRunItems);

        List< com.kejiguan.ui.widget.BarChartView.BarChartItemBean> beanList=new ArrayList<>();
        for (ExhibitionRunItem exhibitionRunItem:backExhibitionRunItems)
        {
            beanList.add(new com.kejiguan.ui.widget.BarChartView.BarChartItemBean(exhibitionRunItem.getDisplayName(), exhibitionRunItem.getValue(type)));
        }
        int size = beanList.size();
        com.kejiguan.ui.widget.BarChartView.BarChartItemBean[] items = (com.kejiguan.ui.widget.BarChartView.BarChartItemBean[])beanList.toArray(new com.kejiguan.ui.widget.BarChartView.BarChartItemBean[size]);

        barChartView.setItems(items);

    }

    private void getIntentData()
    {
        exhibitionRunItems= (List<ExhibitionRunItem>) getIntent().getSerializableExtra("exhibitionRunItems");
        type=getIntent().getIntExtra("type",1);
    }


    private void generateData()
    {

        switch (type)
        {
            case 1://电压
                titleView.setText("展项电压统计");
                break;
            case 2://温度
                titleView.setText("展项运行温度统计");
                break;
            case 3://按钮次数
                titleView.setText("展项按钮次数统计");
                break;
            case 4://旋钮次数
                titleView.setText("展项旋转次数统计");
                break;
            case 5://手柄次数
                titleView.setText("展项手柄次数统计");
                break;
            case 6://机构次数
                titleView.setText("展项机构次数统计");
                break;
            case 7://电流
                titleView.setText("展项电流统计");
                break;
        }


    }



}
